package cc.example.mybatislike.config;

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;

@Configuration
public class GormConfig {
  @Bean(name = "gormDataSource")
  @Qualifier("gormDataSource")
  @ConfigurationProperties("spring.datasource.gorm")
  public DataSource dataSourceIaas() {
    return new HikariDataSource();
  }

  @Bean(name = "gormJdbcTemplate")
  public NamedParameterJdbcTemplate gormJdbcTemplate(@Qualifier("gormDataSource") DataSource gormDataSource) throws Exception {
    return new NamedParameterJdbcTemplate(gormDataSource);
  }
}
